using System.Collections.Generic;
using System.Linq;
using C3.Proto.Core.Model;
using C3.Proto.Core.Repository;
using SubSonic.Repository;

namespace C3.Proto.Repo
{
    public abstract class RepositoryBase : IRepositoryBase
    {
        protected readonly SimpleRepository repo = new SimpleRepository("DBO2Safety");

        public T GetById<T>(int id) where T : Root, new()
        {
            return repo.Single<T>(t => t.Id == id);
        }

        public IList<T> GetAll<T>() where T : class, new()
        {
            return repo.All<T>().ToList();
        }

        public void Add<T>(T item) where T : class, new()
        {
            repo.Add<T>(item);
        }

        public void Delete<T>(int key) where T : class, new()
        {
            repo.Delete<T>(key);
        }

        public int Update<T>(T item) where T : class, new()
        {
            return repo.Update<T>(item);
        }
    }
}